package com.acwing.partition19;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/1/26 17:05
 */
public class AC1843圆形牛棚_dp {

    private static final int N = 1010;
    private static int[] nums = new int[N], dp = new int[N];
    private static int n = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        //s0=0*a0+1*a1+2*a2+3*a3+4*a4+5*a5
        //s1=0*a1+1*a2+2*a3+3*a4+4*a5+5*a0
        //s0-s1=a1+a2+a3+a4+a5-5a0 => s0-s1=a0+a1+a2+a3+a4+a5-6a0 => s0-s1=sum-6*a0，得s1=s0-sum+n*a[i-1]
        int sum = 0, ans = 0;
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(reader.readLine());
            sum += nums[i];
            ans += i * nums[i];
        }
        dp[0] = ans;
        for (int i = 1; i < n; i++) {
            dp[i] = dp[i - 1] - sum + n * nums[i - 1];
            ans = Math.min(ans, dp[i]);
        }
        writer.write(ans + "\n");
        writer.flush();
    }
}
